

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/blog/img/fluid.png">
  <link rel="icon" href="/blog/images/base.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="Airfe">
  <meta name="keywords" content="">
  
    <meta name="description" content="本文总结了项目中常用到的网页布局方式">
<meta property="og:type" content="article">
<meta property="og:title" content="网页布局方式">
<meta property="og:url" content="https://airfe.gitee.io/blog/2023/06/13/%E7%BD%91%E9%A1%B5%E5%B8%83%E5%B1%80%E6%96%B9%E5%BC%8F/index.html">
<meta property="og:site_name" content="Airfe的博客">
<meta property="og:description" content="本文总结了项目中常用到的网页布局方式">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://markdown-1307246189.cos.ap-chongqing.myqcloud.com/pageImage/%E5%93%8D%E5%BA%94%E5%BC%8F%E7%BD%91%E9%A1%B5%E8%AE%BE%E8%AE%A1.jpg">
<meta property="article:published_time" content="2023-06-13T00:00:00.000Z">
<meta property="article:modified_time" content="2024-02-26T12:24:55.182Z">
<meta property="article:author" content="Airfe">
<meta property="article:tag" content="网页布局方式">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://markdown-1307246189.cos.ap-chongqing.myqcloud.com/pageImage/%E5%93%8D%E5%BA%94%E5%BC%8F%E7%BD%91%E9%A1%B5%E8%AE%BE%E8%AE%A1.jpg">
  
  
  
    <meta name="referrer" content="no-referrer" />
  
  <title>网页布局方式 - Airfe的博客</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/blog/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/blog/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/blog/css/highlight-dark.css" />
  




  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"airfe.gitee.io","root":"/blog/","version":"1.9.4","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":true,"follow_dnt":true,"baidu":"699a5d71ac7179b23874a59b0666a6f6","google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":"RW68dMkEpeIOJJiBr1lPkhOS-gzGzoHsz","app_key":"P5fzMTGSJIoTaGvmgzsUHeNZ","server_url":"https://rw68dmke.lc-cn-n1-shared.com","path":"window.location.pathname","ignore_local":false}},"search_path":"/blog/local-search.xml"};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/blog/js/utils.js" ></script>
  <script  src="/blog/js/color-schema.js" ></script>
  

  
    <!-- Baidu Analytics -->
    <script async>
      if (!Fluid.ctx.dnt) {
        var _hmt = _hmt || [];
        (function() {
          var hm = document.createElement("script");
          hm.src = "https://hm.baidu.com/hm.js?699a5d71ac7179b23874a59b0666a6f6";
          var s = document.getElementsByTagName("script")[0];
          s.parentNode.insertBefore(hm, s);
        })();
      }
    </script>
  

  

  

  

  

  

  
    
  



  
<meta name="generator" content="Hexo 6.3.0"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/blog/">
      <strong>Airfe</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/blog/">
                <i class="iconfont icon-home-fill"></i>
                <span>首页</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/blog/archives/">
                <i class="iconfont icon-archive-fill"></i>
                <span>归档</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/blog/categories/">
                <i class="iconfont icon-category-fill"></i>
                <span>分类</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/blog/tags/">
                <i class="iconfont icon-tags-fill"></i>
                <span>标签</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/blog/about/">
                <i class="iconfont icon-user-fill"></i>
                <span>关于</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/blog/links/">
                <i class="iconfont icon-link-fill"></i>
                <span>友链</span>
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              <i class="iconfont icon-search"></i>
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">
              <i class="iconfont icon-dark" id="color-toggle-icon"></i>
            </a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/blog/images/bg.jpg') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="网页布局方式"></span>
          
        </div>

        
          
  <div class="mt-3">
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2023-06-13 08:00" pubdate>
          2023年06月13日
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          7.6k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          63 分钟
        
      </span>
    

    
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">网页布局方式</h1>
            
            
              <div class="markdown-body">
                
                <h1 id="一、传统网页布局总结"><a href="#一、传统网页布局总结" class="headerlink" title="一、传统网页布局总结"></a>一、传统网页布局总结</h1><p>传统网络布局三种方式：标准流、浮动、定位。（重点：定位）</p>
<h2 id="1-标准流"><a href="#1-标准流" class="headerlink" title="1. 标准流"></a>1. 标准流</h2><ul>
<li>块级元素会独占一行，从上向下顺序排列。</li>
<li>行内元素会按照顺序，从左到右顺序排列，碰到父元素边缘则自动换行。</li>
</ul>
<h2 id="2-浮动（-x3D-x3D-脱标-x3D-x3D-）"><a href="#2-浮动（-x3D-x3D-脱标-x3D-x3D-）" class="headerlink" title="2. 浮动（&#x3D;&#x3D;脱标&#x3D;&#x3D;）"></a>2. 浮动（&#x3D;&#x3D;脱标&#x3D;&#x3D;）</h2><ul>
<li>可以让多个块级元素一行内排列显示。</li>
<li>&#x3D;&#x3D;float属性用于创建浮动框，将其移动到一边，直到左边缘或右边缘触及包含块或另一个浮动框的边缘。&#x3D;&#x3D;</li>
<li>为了约束浮动元素位置我们网页布局一般采取的策略是: 先用标准流的父元素排列，上下位置，之后内部子元素采取浮动排列左右位置。</li>
</ul>
<blockquote>
<p>网页布局第一准则: 多个块级元素纵向排列找标准流，多个块级元素横向排列找浮动。（标准流管上下，浮动管左右）</p>
</blockquote>
<ul>
<li><p>为什么要清除浮动(父盒子没高度，子浮动了，影响了下面布局)</p>
<ul>
<li><p>Why：由于父级盒子很多情况下，不方便给高度，但是子盒子浮动又不占有位置，最后父级盒子高度为0时，就会<br>影响下面的标准流盒子。</p>
</li>
<li><p>如果父盒子本身有高度，则不需要清除浮动。</p>
</li>
<li><p>清除浮动之后，父级就会根据浮动的子盒子自动检测高度。父级有了高度，就不会影响下面的标准流了。</p>
</li>
<li><p>语法</p>
<blockquote>
<p>选择器{clear:属性值；}</p>
<p>left | right | both</p>
</blockquote>
</li>
</ul>
</li>
<li><p>&#x3D;&#x3D;清除浮动的方法&#x3D;&#x3D;</p>
<ul>
<li><p>额外标签法（隔墙法）</p>
<ul>
<li>在浮动元素末尾添加一个空的标签。例如<div style="clear:both"> </div></li>
</ul>
</li>
<li><p>父级添加overflow属性</p>
</li>
<li><p>父级添加:after伪元素</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><code class="hljs css"><span class="hljs-selector-class">.clearfix</span><span class="hljs-selector-pseudo">:after</span> &#123;<br>    <span class="hljs-attribute">content</span>:<span class="hljs-string">&#x27;&#x27;</span>;  //伪元素必须写的属性<br>    <span class="hljs-attribute">display</span>:block;//插入的元素必须是块级<br>    <span class="hljs-attribute">height</span>: <span class="hljs-number">0</span>;//不要看见这个元素<br>    <span class="hljs-attribute">clear</span>: both; //核心代码清除浮动<br>    <span class="hljs-attribute">visibility</span>: hidden; //不要看见这个元素<br>&#125;<br><br><span class="hljs-selector-class">.clearfix</span> &#123; <span class="hljs-comment">/* IE6、7专有*/</span><br>    *zoom: <span class="hljs-number">1</span>;<br>&#125;<br><br>&lt;<span class="hljs-selector-tag">div</span> class=&quot;box clearfix&quot;&gt;<br>    &lt;<span class="hljs-selector-tag">div</span> class=&quot;damao&quot;&gt; 大毛&lt;/<span class="hljs-selector-tag">div</span>&gt;<br>    &lt;<span class="hljs-selector-tag">div</span> class=&quot;ermao&quot;&gt; 二毛&lt;/<span class="hljs-selector-tag">div</span>&gt;<br>&lt;<span class="hljs-selector-tag">div</span> class=&quot;<span class="hljs-selector-tag">footer</span>&quot;&gt;&lt; /<span class="hljs-selector-tag">div</span>&gt;<br></code></pre></td></tr></table></figure>
</li>
<li><p>父级添加双伪元素</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><code class="hljs css"><span class="hljs-selector-class">.clearfix</span><span class="hljs-selector-pseudo">:before</span>,<span class="hljs-selector-class">.clearfix</span><span class="hljs-selector-pseudo">:after</span> &#123;<br>    <span class="hljs-attribute">content</span>: <span class="hljs-string">&quot;&quot;</span>;<br>    <span class="hljs-attribute">display</span>:table; //转化为块级元素并且一行显示<br>&#125;<br><span class="hljs-selector-class">.clearfix</span><span class="hljs-selector-pseudo">:after</span> &#123;<br>    <span class="hljs-attribute">clear</span>:both;<br>&#125;<br></code></pre></td></tr></table></figure></li>
</ul>
</li>
</ul>
<h2 id="3-定位"><a href="#3-定位" class="headerlink" title="3. 定位"></a>3. 定位</h2><p><a target="_blank" rel="noopener" href="https://www.bilibili.com/video/BV14J4114768?p=235&vd_source=eecaca8f9a8f0e789df0ded617e5100a">学习视频</a></p>
<p><strong>相对定位</strong></p>
<blockquote>
<p>选择器{position: relative; }</p>
<ul>
<li>它是相对于自己原来的位置来移动的(&#x3D;&#x3D;移动位置的时候参照点是自己原来的位置&#x3D;&#x3D;)。</li>
<li>原来在标准流的位置继续占有，后面的盒子仍然以标准流的方式对待它。(&#x3D;&#x3D;不脱标&#x3D;&#x3D;, 继续保留原来位置)</li>
</ul>
</blockquote>
<p><strong>绝对定位</strong></p>
<blockquote>
<p>选择器{position: absolute; }</p>
<ul>
<li>绝对定位是元素在移动位置的时候,是相对于它&#x3D;&#x3D;有定位的祖先元素&#x3D;&#x3D;来说的。</li>
<li>如果没有祖先元素或者祖先元素没有定位，则以浏览器为准定位( &#x3D;&#x3D;脱标&#x3D;&#x3D;、行内可以设置宽高，块元素不独占一行，由内容撑开宽高；)</li>
</ul>
</blockquote>
<p>与浮动区别：</p>
<ul>
<li>浮动可以让多个块级盒子一行没有缝隙排列显示，经常用于横向排列盒子。</li>
<li>定位则是可以让盒子自由的在某个盒子内移动位置或者固定屏幕中某个位置，并且可以压住其他盒子。</li>
<li>浮动元素不同，只会压住它下面标准流的盒子，但是不会压住下面标准流盒子里面的文字(图片)</li>
<li>但是绝对定位(固定定位)会压住下面标准流所有的内容。</li>
</ul>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><code class="hljs css">&lt;head&gt;<br>    &lt;style&gt;<br>        <span class="hljs-selector-class">.box</span> &#123;<br>            <span class="hljs-comment">/* 1.浮动的元素不会压住下面标准流的文字*/</span><br>            <span class="hljs-comment">/* fLoat: Left; */</span><br>            <span class="hljs-comment">/* 2.绝对定位(固定定位) 全压住下面标准流所有的内容。</span><br><span class="hljs-comment">            position: absolute;</span><br><span class="hljs-comment">            width: 150px;</span><br><span class="hljs-comment">            height: 150px;</span><br><span class="hljs-comment">            background-color:pink;</span><br><span class="hljs-comment">        &#125;</span><br><span class="hljs-comment">    &lt;/style&gt;</span><br><span class="hljs-comment">&lt;/head&gt;</span><br><span class="hljs-comment">&lt;body&gt;</span><br><span class="hljs-comment">    &lt;div class=&quot;box&quot;&gt;&lt;/div&gt;</span><br><span class="hljs-comment">    &lt;p&gt;阁下何不同风起，扶摇直上九万里&lt;/p&gt;</span><br><span class="hljs-comment">&lt;/bodv&gt;</span><br></code></pre></td></tr></table></figure>

<p><strong>固定定位</strong></p>
<p>固定定位是绝对定位的一种特殊形式，也是&#x3D;&#x3D;脱标&#x3D;&#x3D;的，并且只认浏览器的可视窗口，与父元素无关</p>
<ul>
<li>在使用固定定位时，如果盒子中没有内容，需要指定宽度</li>
</ul>
<h2 id="4-总结"><a href="#4-总结" class="headerlink" title="4. 总结"></a>4. 总结</h2><p>绝对定位和固定定位与浮动相同的地方：</p>
<ul>
<li>行内元素添加绝对或者固定定位，可以直接设置高度和宽度（脱标）。</li>
<li>块级元素添加绝对或者固定定位，如果不给宽度或者高度,默认大小是内容的大小。</li>
</ul>
<table>
<thead>
<tr>
<th>定位模式</th>
<th>是否脱标</th>
<th>移动位置</th>
<th>是否常用</th>
</tr>
</thead>
<tbody><tr>
<td>static静态定位</td>
<td>否（占有位置）</td>
<td>不能使用边偏移</td>
<td>很少</td>
</tr>
<tr>
<td>relative相对定位</td>
<td>否（占有位置）</td>
<td>相对于自身位置移动</td>
<td>常用</td>
</tr>
<tr>
<td>absolute绝对定位</td>
<td>是（不占有位置）</td>
<td>带有定位的父级</td>
<td>常用</td>
</tr>
<tr>
<td>fixed固定定位</td>
<td>是（不占有位置）</td>
<td>浏览器可视区</td>
<td>常用</td>
</tr>
<tr>
<td>sticky粘性定位</td>
<td>否（占有位置）</td>
<td>浏览器可视区</td>
<td>很少</td>
</tr>
</tbody></table>
<p>&#x3D;&#x3D;重点：子绝父相&#x3D;&#x3D;</p>
<p>注意的点：</p>
<ol>
<li><p>标准流（如相对定位）可以用margin：0 auto来水平居中；但脱离标准流以后水平居中要采用，left：50%；margin-left：-自身宽度一半&#x3D;&#x3D; transform: translate(-50%,-50%);（往左往上移动自身宽度一半）</p>
</li>
<li><p>z-index用来控制叠放次序：</p>
<p>在使用定位布局时，可能会出现盒子重叠的情况。此时可以用<strong>z-indx</strong>来控制盒子的先后次序（z轴）</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs css">选择器 &#123;<span class="hljs-attribute">z-index</span>:<span class="hljs-number">1</span>;&#125;<br></code></pre></td></tr></table></figure>

<ul>
<li>数值可以是正整数、负整数或0，默认是auto ，数值越大，盒子越靠上</li>
<li>如果属性值相同，则按照书写顺序，后来居上</li>
<li>数字后面不能加单位</li>
<li>只有定位的盒子才有z-index属性</li>
</ul>
</li>
</ol>
<ul>
<li>传统网页布局总结:<ul>
<li>标准流<br>可以让盒子上下排列或者左右排列,垂直的块级盒子显示就用标准流布局。</li>
<li>浮动<br>可以让多个块级元素-行显示或者左右对齐盒子 ,多个块级盒子水平显示就用浮动布局。</li>
<li>定位<br>定位最大的特点是有层叠的概念,就是可以让多个盒子前后叠压来显示。如果元素自由在某个盒子内移动就<br>用定位布局。</li>
</ul>
</li>
</ul>
<h1 id="二、FLEX布局"><a href="#二、FLEX布局" class="headerlink" title="二、FLEX布局"></a>二、FLEX布局</h1><p>通过给&#x3D;&#x3D;父元素添加&#x3D;&#x3D;flex属性制子元素的排列方式和位置。</p>
<blockquote>
<p>注意，设为 Flex 布局以后，子元素的<code>float</code>、<code>clear</code>和<code>vertical-align</code>属性将失效。</p>
</blockquote>
<h2 id="父项常见属性"><a href="#父项常见属性" class="headerlink" title="父项常见属性"></a><strong>父项常见属性</strong></h2><ul>
<li>flex-direction：设置主轴的方向</li>
<li>flex-wrap：设置子元素是否换行</li>
<li>flex-flow：复合属性，相当于同时设置了flex-direction和flex-wrap</li>
<li>justify-content：设置主轴上的子元素排列方式</li>
<li>align-items：设置侧轴上的子元素排列方式(单行)</li>
<li>align-content：设置侧轴上的子元素的排列方式(多行)</li>
</ul>
<ol>
<li><p>flex-direction：默认的主轴是x轴行row，y轴column列是侧轴，子元素是根据主轴来排列的。</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs css"><span class="hljs-selector-class">.box</span> &#123;<br>  <span class="hljs-attribute">flex-direction</span>: row | row-reverse | column | column-reverse;<br>&#125;<br></code></pre></td></tr></table></figure>
</li>
<li><p>flex-wrap：设置子元素是否换行，flex布局默认不换行。如果装不开会缩小子元素的宽度。</p>
<ul>
<li>wrap：   换行， 第一行在上方。</li>
<li>nowrap：不换行（默认）</li>
<li>wrap-reverse：换行，第一行在下方。</li>
<li><strong>设置了换行以后才可使用align-content</strong></li>
</ul>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs css">// 设置每行显示的个数，超出自动换行解决方案<br>// 父元素<br><span class="hljs-attribute">flex-wrap</span>: wrap;<br>// 子元素设置宽度使一行放不下三个就会自动换行<br><span class="hljs-attribute">min-width</span>: <span class="hljs-number">48%</span>;<br></code></pre></td></tr></table></figure>
</li>
<li><p>flex-flow：是flex-direction和flex-wrap的复合属性。</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs css"><span class="hljs-selector-class">.box</span> &#123;<br>  <span class="hljs-attribute">flex-flow</span>: &lt;flex-direction&gt; || &lt;flex-wrap&gt;;<br>&#125;<br></code></pre></td></tr></table></figure>
</li>
<li><p>justify-content：设置主轴上的子元素排列方式。</p>
<ul>
<li>flex-start:                从左到右</li>
<li>flex-end:                 从右到左</li>
<li>center:                    居中对齐</li>
<li>space-around:       平均分配（相当于每个盒子的marginleft right相等）</li>
<li><strong>space-between</strong>:     先两边贴边，再平分剩余空间，项目之间的间隔都相等</li>
</ul>
</li>
<li><p>align-items：设置侧轴上的子元素排列方式（&#x3D;&#x3D;单行&#x3D;&#x3D;）。以主轴为x，侧轴为y轴为例：</p>
<ul>
<li>flex-start:  从上到下 </li>
<li>flex-end:   从下到上</li>
<li>center:      挤在一起居中（垂直居中）</li>
<li>stretch:     拉伸（默认值）</li>
</ul>
<img src="" srcset="/blog/img/loading.gif" lazyload data-original="https://markdown-1307246189.cos.ap-chongqing.myqcloud.com/%20markdown/image-20230613135026452.png" alt="image-20230613135026452" style="zoom:80%;">
</li>
<li><p>align-content：设置侧轴上的子元素的排列方式(&#x3D;&#x3D;多行&#x3D;&#x3D;，在单行情况下没效果)。</p>
<ul>
<li>flex-start:               从侧轴的头部开始排列</li>
<li>flex-end:                 从侧轴的尾部开始排列</li>
<li>center:                    在侧轴中间显示</li>
<li>space-around:       子项在侧轴平分剩余空间</li>
<li>space-between:     子项在侧轴先分布在两头，再平分剩余空间</li>
<li>stretch：                 设置子项元素高度平分父元素高度。</li>
</ul>
<img src="" srcset="/blog/img/loading.gif" lazyload data-original="https://markdown-1307246189.cos.ap-chongqing.myqcloud.com/%20markdown/image-20230613135224902.png" alt="image-20230613135224902" style="zoom:80%;"></li>
</ol>
<h2 id="子项常见属性"><a href="#子项常见属性" class="headerlink" title="子项常见属性"></a><strong>子项常见属性</strong></h2><ul>
<li>order：定义项目的排列顺序，数值越小排列越靠前，默认为0</li>
<li>flex-grow：属性定义项目的放大比例，默认为<code>0</code>，即如果存在剩余空间，也不放大。</li>
<li>flex-shrink：定义了项目的缩小比例，默认为1，即如果空间不足，该项目将缩小。</li>
<li>flex-basis：定义了在分配多余空间之前，项目占据的主轴空间（main size）。浏览器根据这个属性，计算主轴是否有多余空间。它的默认值为<code>auto</code>，即项目的本来大小。</li>
<li><strong>flex</strong>：<code>flex-grow</code>, <code>flex-shrink</code> 和 <code>flex-basis</code>的简写，默认值为<code>0 1 auto</code>。后两个属性可选。</li>
<li>align-self：<code>align-self</code>属性允许单个项目有与其他项目不一样的对齐方式，可覆盖<code>align-items</code>属性。默认值为<code>auto</code>，表示继承父元素的<code>align-items</code>属性，如果没有父元素，则等同于<code>stretch</code>。</li>
</ul>
<ol>
<li><p>order</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs css"><span class="hljs-selector-class">.item</span> &#123;<br>  <span class="hljs-attribute">order</span>: &lt;integer&gt;;<br>&#125;<br></code></pre></td></tr></table></figure>
</li>
<li><p>flex-grow 定义项目的放大比例</p>
<blockquote>
<p>如果所有项目的<code>flex-grow</code>属性都为1，则它们将等分剩余空间（如果有的话）。如果一个项目的<code>flex-grow</code>属性为2，其他项目都为1，则前者占据的剩余空间将比其他项多一倍。</p>
</blockquote>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs css"><span class="hljs-selector-class">.item</span> &#123;<br>  <span class="hljs-attribute">flex-grow</span>: &lt;number&gt;; <span class="hljs-comment">/* default 0 */</span><br>&#125;<br></code></pre></td></tr></table></figure>

<p><img src="" srcset="/blog/img/loading.gif" lazyload data-original="https://markdown-1307246189.cos.ap-chongqing.myqcloud.com/%20markdown/image-20230613135819114.png" alt="image-20230613135819114"></p>
</li>
<li><p>flex-shrink</p>
<blockquote>
<p>如果所有项目的<code>flex-shrink</code>属性都为1，当空间不足时，都将等比例缩小。如果一个项目的<code>flex-shrink</code>属性为0，其他项目都为1，则空间不足时，前者不缩小。</p>
</blockquote>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs css"><span class="hljs-selector-class">.item</span> &#123;<br>  <span class="hljs-attribute">flex-shrink</span>: &lt;number&gt;; <span class="hljs-comment">/* default 1 */</span><br>&#125;<br></code></pre></td></tr></table></figure>
</li>
<li><p>flex-basis</p>
<p>在分配多余空间之前，项目占据的主轴空间。以x轴为例</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><code class="hljs css">&lt;<span class="hljs-selector-tag">div</span> class=&quot;box1&quot;&gt;<br>    &lt;<span class="hljs-selector-tag">div</span> class=&quot;item&quot; style=&quot;<span class="hljs-attribute">flex</span>: <span class="hljs-number">1</span>;<span class="hljs-attribute">background-color</span>: red;&quot;&gt;&lt;/<span class="hljs-selector-tag">div</span>&gt;<br>    &lt;<span class="hljs-selector-tag">div</span> class=&quot;item&quot; style=&quot;<span class="hljs-attribute">flex</span>: <span class="hljs-number">1</span>;<span class="hljs-attribute">background-color</span>: black;<span class="hljs-attribute">flex-basis</span>: <span class="hljs-number">10px</span><span class="hljs-string">&quot;&gt;&lt;/div&gt;</span><br><span class="hljs-string">    &lt;div class=&quot;</span>item<span class="hljs-string">&quot; style=&quot;</span>flex: <span class="hljs-number">1</span>;<span class="hljs-attribute">background-color</span>: pink;&quot;&gt;&lt;/<span class="hljs-selector-tag">div</span>&gt;<br>&lt;/<span class="hljs-selector-tag">div</span>&gt;<br><br><span class="hljs-selector-class">.box1</span> &#123;<br>        <span class="hljs-attribute">width</span>: <span class="hljs-number">100px</span>;<br>        <span class="hljs-attribute">height</span>: <span class="hljs-number">30px</span>;<br>        <span class="hljs-attribute">display</span>: flex;<br>        <span class="hljs-attribute">justify-content</span>: space-between;<br>        <span class="hljs-attribute">background-color</span>: green;<br>    &#125;<br><span class="hljs-selector-class">.item</span> &#123;<br>    <span class="hljs-attribute">height</span>: <span class="hljs-number">100%</span>;<br>&#125;<br>// 第二个item给了<span class="hljs-number">10px</span>的宽度，则原本他就占据主轴的<span class="hljs-number">10px</span>，总宽度<span class="hljs-number">100px</span>-<span class="hljs-number">10px</span>=<span class="hljs-number">90px</span>，再根据<span class="hljs-attribute">flex</span>=<span class="hljs-number">1</span>平分剩余空间，最终三项的宽度为<span class="hljs-number">30px</span>、<span class="hljs-number">40px</span>、<span class="hljs-number">30px</span><br></code></pre></td></tr></table></figure>

<p><img src="" srcset="/blog/img/loading.gif" lazyload data-original="https://markdown-1307246189.cos.ap-chongqing.myqcloud.com/%20markdown/image-20230613143303345.png" alt="image-20230613143303345"></p>
</li>
<li><p><strong>flex</strong></p>
<p>是flex-grow，flex-shrink，flex-basis的简写，默认值为0 1 auto。后两个属性可选。</p>
<p>建议优先使用这个属性，而不是单独写三个分离的属性，因为浏览器会推算相关值。</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><code class="hljs css">&lt;<span class="hljs-selector-tag">div</span> class=&quot;box1&quot;&gt;<br>    &lt;<span class="hljs-selector-tag">div</span> class=&quot;item&quot; style=&quot;<span class="hljs-attribute">flex</span>: <span class="hljs-number">1</span>;<span class="hljs-attribute">background-color</span>: red;&quot;&gt;&lt;/<span class="hljs-selector-tag">div</span>&gt;<br>    &lt;<span class="hljs-selector-tag">div</span> class=&quot;item&quot; style=&quot;<span class="hljs-attribute">flex</span>: <span class="hljs-number">2</span>;<span class="hljs-attribute">background-color</span>: black;&quot;&gt;&lt;/<span class="hljs-selector-tag">div</span>&gt;<br>    &lt;<span class="hljs-selector-tag">div</span> class=&quot;item&quot; style=&quot;<span class="hljs-attribute">flex</span>: <span class="hljs-number">1</span>;<span class="hljs-attribute">background-color</span>: pink;&quot;&gt;&lt;/<span class="hljs-selector-tag">div</span>&gt;<br>&lt;/<span class="hljs-selector-tag">div</span>&gt;<br><br>&lt;style&gt;<br>    <span class="hljs-selector-class">.box1</span> &#123;<br>        <span class="hljs-attribute">width</span>: <span class="hljs-number">100px</span>;<br>        <span class="hljs-attribute">height</span>: <span class="hljs-number">30px</span>;<br>        <span class="hljs-attribute">display</span>: flex;<br>        <span class="hljs-attribute">justify-content</span>: space-between;<br>        <span class="hljs-attribute">background-color</span>: green;<br>    &#125;<br>    <span class="hljs-selector-class">.item</span> &#123;<br>        <span class="hljs-attribute">height</span>: <span class="hljs-number">100%</span>;<br>    &#125;<br>&lt;/style&gt;<br></code></pre></td></tr></table></figure>

<p>该属性有两个快捷值：<code>auto</code> (<code>1 1 auto</code>) 和 none (<code>0 0 auto</code>)。</p>
<p><img src="" srcset="/blog/img/loading.gif" lazyload data-original="https://markdown-1307246189.cos.ap-chongqing.myqcloud.com/%20markdown/image-20230613142215388.png" alt="image-20230613142215388"></p>
</li>
<li><p>align-self：控制子项自己在侧轴上的排列方式。</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs css"><span class="hljs-selector-class">.item</span> &#123;<br>  <span class="hljs-attribute">align-self</span>: auto | flex-start | flex-end | center | baseline | stretch;<br>&#125;<br></code></pre></td></tr></table></figure></li>
</ol>
<img src="" srcset="/blog/img/loading.gif" lazyload data-original="https://markdown-1307246189.cos.ap-chongqing.myqcloud.com/%20markdown/image-20230613141142829.png" alt="image-20230613141142829" style="zoom:80%;">

<h1 id="三、居中布局"><a href="#三、居中布局" class="headerlink" title="三、居中布局"></a>三、居中布局</h1><p><strong>标准流：</strong> </p>
<ul>
<li><p>行内元素和行内块元素</p>
<ul>
<li><p>文本水平居中： 给包含文本的标签元素设置<code>text-align: center</code> </p>
</li>
<li><p>文本垂直居中： line-height&#x3D;行高 </p>
</li>
<li><p>行内块元素垂直方向上基线对齐方式：vertical-align，参考的是这一行中的文本</p>
<ul>
<li><p>vertical-align: top; 把这一行的所有元素的顶端与行中最高元素的顶端对齐</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><code class="hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;box1&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">sqan</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;box2&quot;</span>&gt;</span><br>    中文字体<br><span class="hljs-tag">&lt;/<span class="hljs-name">sqan</span>&gt;</span><br><br><br><span class="hljs-tag">&lt;<span class="hljs-name">style</span>&gt;</span><span class="language-css"></span><br><span class="language-css">    <span class="hljs-selector-class">.box1</span> &#123;</span><br><span class="language-css">        <span class="hljs-attribute">width</span>: <span class="hljs-number">200px</span>;</span><br><span class="language-css">        <span class="hljs-attribute">height</span>: <span class="hljs-number">100px</span>;</span><br><span class="language-css">        <span class="hljs-attribute">display</span>: inline-block;</span><br><span class="language-css">        <span class="hljs-attribute">background-color</span>: green;</span><br><span class="language-css">    &#125;</span><br><span class="language-css">    <span class="hljs-selector-class">.box2</span> &#123;</span><br><span class="language-css">        <span class="hljs-attribute">vertical-align</span>: top;</span><br><span class="language-css">        <span class="hljs-attribute">background-color</span>: red;</span><br><span class="language-css">    &#125;</span><br><span class="language-css"></span><span class="hljs-tag">&lt;/<span class="hljs-name">style</span>&gt;</span><br></code></pre></td></tr></table></figure>

<p><img src="" srcset="/blog/img/loading.gif" lazyload data-original="https://markdown-1307246189.cos.ap-chongqing.myqcloud.com/%20markdown/image-20230613104306222.png" alt="image-20230613104306222"></p>
</li>
<li><p>vertical-align: bottom; 把这一行的所有元素的底端与行中最低元素的底端对齐</p>
</li>
<li><p>vertical-align: baseline; 图片或inline-block元素的底端（图片、inline-block元素底部和基线已经重合）对齐文本的baseline基线对齐  默认值</p>
</li>
<li><p><strong>vertical-align: middle</strong>; 这行元素的中线对齐，图片的中线就是图片垂直方向上一半的位置，文字也是，设置在图片或者inline-block元素上生效</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><code class="hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;box1&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">sqan</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;box2&quot;</span>&gt;</span><br>    中文字体<br><span class="hljs-tag">&lt;/<span class="hljs-name">sqan</span>&gt;</span><br><br><span class="hljs-tag">&lt;<span class="hljs-name">style</span>&gt;</span><span class="language-css"></span><br><span class="language-css">    <span class="hljs-selector-class">.box1</span> &#123;</span><br><span class="language-css">        <span class="hljs-attribute">width</span>: <span class="hljs-number">200px</span>;</span><br><span class="language-css">        <span class="hljs-attribute">height</span>: <span class="hljs-number">100px</span>;</span><br><span class="language-css">        <span class="hljs-attribute">display</span>: inline-block;</span><br><span class="language-css">        <span class="hljs-attribute">background-color</span>: green;</span><br><span class="language-css">        <span class="hljs-attribute">vertical-align</span>: middle;</span><br><span class="language-css">    &#125;</span><br><span class="language-css">    <span class="hljs-selector-class">.box2</span> &#123;</span><br><span class="language-css">        <span class="hljs-attribute">background-color</span>: red;</span><br><span class="language-css">    &#125;</span><br><span class="language-css"></span><span class="hljs-tag">&lt;/<span class="hljs-name">style</span>&gt;</span><br></code></pre></td></tr></table></figure>

<p><img src="" srcset="/blog/img/loading.gif" lazyload data-original="https://markdown-1307246189.cos.ap-chongqing.myqcloud.com/%20markdown/image-20230613105844576.png" alt="image-20230613105844576"></p>
</li>
<li><p>vertical-align: super;  使元素基线高于父元素基线，但是高多少规范中没有要求，由用户代理（浏览器）自己决定，不同浏览器可能不同。<br>vertical-align: sub;  使元素基线低于父元素基线，与 super 一样，低多少由用户代理决定，不同浏览器可能不同。</p>
</li>
</ul>
</li>
</ul>
</li>
<li><p>块级元素</p>
<ul>
<li>水平居中：<code> margin: 0 auto</code>（要求定宽）；设置display:table和margin:0 auto（不定宽）</li>
<li>垂直居中：只能通过flex布局或定位实现。</li>
</ul>
</li>
</ul>
<p>绝对定位脱标以后：(块级元素定位实现垂直居中)</p>
<p>水平居中：left：50%; margin-left:-自身宽度一半；&#x3D;&#x3D;  left:50%； transform:translate(-50%,0);</p>
<p>垂直居中：top：50%；margin-top：-自身高度一半 ；&#x3D;&#x3D; top:50%； transform:translate(0,-50%);</p>
<p>水平垂直居中：left:50%; top:50%; transform:translate(-50%,-50%);</p>
<h1 id="参考"><a href="#参考" class="headerlink" title="参考"></a>参考</h1><p><a target="_blank" rel="noopener" href="https://www.ruanyifeng.com/blog/2015/07/flex-grammar.html">阮一峰的网络日志</a></p>

                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/blog/categories/%E5%89%8D%E7%AB%AF%E6%8A%80%E6%9C%AF%E6%A0%88/" class="category-chain-item">前端技术栈</a>
  
  
    <span>></span>
    
  <a href="/blog/categories/%E5%89%8D%E7%AB%AF%E6%8A%80%E6%9C%AF%E6%A0%88/css/" class="category-chain-item">css</a>
  
  

  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/blog/tags/%E7%BD%91%E9%A1%B5%E5%B8%83%E5%B1%80%E6%96%B9%E5%BC%8F/">#网页布局方式</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>网页布局方式</div>
      <div>https://airfe.gitee.io/blog/2023/06/13/网页布局方式/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>Airfe</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2023年6月13日</div>
        </div>
      
      
      
        <div class="license-meta-item">
          <div>许可协议</div>
          <div>
            
              
              
                <a target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
                  <span class="hint--top hint--rounded" aria-label="BY - 署名">
                    <i class="iconfont icon-by"></i>
                  </span>
                </a>
              
            
          </div>
        </div>
      
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/blog/2023/06/17/Ajax/" title="Ajax">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">Ajax</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/blog/2023/06/08/%E9%9B%86%E5%90%88%E5%BC%95%E7%94%A8%E7%B1%BB%E5%9E%8BArray/" title="集合引用类型Array">
                        <span class="hidden-mobile">集合引用类型Array</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
  
  
    <article id="comments" lazyload>
      
  <div id="valine"></div>
  <script type="text/javascript">
    Fluid.utils.loadComments('#valine', function() {
      Fluid.utils.createScript('https://lib.baomitu.com/valine/1.5.1/Valine.min.js', function() {
        var options = Object.assign(
          {"appId":"RW68dMkEpeIOJJiBr1lPkhOS-gzGzoHsz","appKey":"P5fzMTGSJIoTaGvmgzsUHeNZ","path":"window.location.pathname","placeholder":"发表你的看法吧~","avatar":"retro","meta":["nick","mail","link"],"requiredFields":[],"pageSize":10,"lang":"zh-CN","highlight":false,"recordIP":false,"serverURLs":"","emojiCDN":null,"emojiMaps":null,"enableQQ":false,"appid":"RW68dMkEpeIOJJiBr1lPkhOS-gzGzoHsz","appkey":"P5fzMTGSJIoTaGvmgzsUHeNZ","server_url":"https://rw68dmke.lc-cn-n1-shared.com"},
          {
            el: "#valine",
            path: window.location.pathname
          }
        )
        new Valine(options);
        Fluid.utils.waitElementVisible('#valine .vcontent', () => {
          var imgSelector = '#valine .vcontent img:not(.vemoji)';
          Fluid.plugins.imageCaption(imgSelector);
          Fluid.plugins.fancyBox(imgSelector);
        })
      });
    });
  </script>
  <noscript>Please enable JavaScript to view the comments</noscript>


    </article>
  


          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header">
    <i class="iconfont icon-list"></i>
    <span>目录</span>
  </p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
        <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> <div style="font-size: 0.85rem"> <span id="timeDate">载入天数</span> <span id="times">载入时分秒</span> <script src="js/duration.js"></script> </div> 
    </div>
  
  
    <div class="statistics">
  
  

  
    
      <span id="leancloud-site-pv-container" style="display: none">
        总访问量 
        <span id="leancloud-site-pv"></span>
         次
      </span>
    
    
      <span id="leancloud-site-uv-container" style="display: none">
        总访客数 
        <span id="leancloud-site-uv"></span>
         人
      </span>
    
    

  
</div>

  
  
    <!-- 备案信息 ICP for China -->
    <div class="beian">
  <span>
    <a href="http://beian.miit.gov.cn/" target="_blank" rel="nofollow noopener">
      蜀ICP备2023008943号
    </a>
  </span>
  
    
      <span>
        <a
          href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=https://beian.miit.gov.cn/"
          rel="nofollow noopener"
          class="beian-police"
          target="_blank"
        >
          
            <span style="visibility: hidden; width: 0">|</span>
            <img src="" srcset="/blog/img/loading.gif" lazyload data-original="/blog/img/police_beian.png" alt="police-icon"/>
          
          <span>京公网安备12345678号</span>
        </a>
      </span>
    
  
</div>

  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.0/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/blog/js/events.js" ></script>
<script  src="/blog/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/blog/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.18.2/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init(Object.assign({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      scrollSmooth    : true,
      includeTitleTags: true,
      headingsOffset  : -boardTop,
    }, CONFIG.toc));
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }

    Fluid.events.registerRefreshCallback(function() {
      if ('tocbot' in window) {
        tocbot.refresh();
        var toc = jQuery('#toc');
        if (toc.length === 0 || !tocbot) {
          return;
        }
        if (toc.find('.toc-list-item').length > 0) {
          toc.css('visibility', 'visible');
        }
      }
    });
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.11/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));

    Fluid.events.registerRefreshCallback(function() {
      if ('anchors' in window) {
        anchors.removeAll();
        var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
        var res = [];
        for (var item of el) {
          res.push('.markdown-body > ' + item.trim());
        }
        if (CONFIG.anchorjs.placement === 'left') {
          anchors.options.class = 'anchorjs-link-left';
        }
        anchors.add(res.join(', '));
      }
    });
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script defer src="/blog/js/leancloud.js" ></script>

  <script  src="/blog/js/local-search.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/blog/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>

        <style>
            [bg-lazy] {
                background-image: none !important;
                background-color: #eee !important;
            }
        </style>
        <script>
            window.imageLazyLoadSetting = {
                isSPA: false,
                preloadRatio: 1,
                processImages: null,
            };
        </script><script>window.addEventListener("load",function(){var t=/\.(gif|jpg|jpeg|tiff|png)$/i,r=/^data:image\/[a-z]+;base64,/;Array.prototype.slice.call(document.querySelectorAll("img[data-original]")).forEach(function(a){var e=a.parentNode;"A"===e.tagName&&(e.href.match(t)||e.href.match(r))&&(e.href=a.dataset.original)})});</script><script>!function(r){r.imageLazyLoadSetting.processImages=t;var e=r.imageLazyLoadSetting.isSPA,n=r.imageLazyLoadSetting.preloadRatio||1,c=a();function a(){var t=Array.prototype.slice.call(document.querySelectorAll("img[data-original]")),e=Array.prototype.slice.call(document.querySelectorAll("[bg-lazy]"));return t.concat(e)}function t(){e&&(c=a());for(var t,o=0;o<c.length;o++)0<=(t=(t=c[o]).getBoundingClientRect()).bottom&&0<=t.left&&t.top<=(r.innerHeight*n||document.documentElement.clientHeight*n)&&function(){var t,e,n,a,i=c[o];e=function(){c=c.filter(function(t){return i!==t}),r.imageLazyLoadSetting.onImageLoaded&&r.imageLazyLoadSetting.onImageLoaded(i)},(t=i).hasAttribute("bg-lazy")?(t.removeAttribute("bg-lazy"),e&&e()):(n=new Image,a=t.getAttribute("data-original"),n.onload=function(){t.src=a,t.removeAttribute("data-original"),e&&e()},t.src!==a&&(n.src=a))}()}function i(){clearTimeout(t.tId),t.tId=setTimeout(t,500)}t(),document.addEventListener("scroll",i),r.addEventListener("resize",i),r.addEventListener("orientationchange",i)}(this);</script></body>
</html>
